package com.geeklei.media.ui.common;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

public class DisplayInformationFetcher {
    public static final int SCREEN_LAND = 0;
    public static final int SCREEN_PORT = 1;
    private static DisplayInformationFetcher sInstance;
    private Display mDefaultDisplay;

    private DisplayInformationFetcher(Context context) {
        this.mDefaultDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    }

    public static DisplayInformationFetcher getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new DisplayInformationFetcher(context);
        }
        return sInstance;
    }

    @SuppressLint({"NewApi"})
    public int getScreenWidth() {
        Point point = new Point();
        this.mDefaultDisplay.getSize(point);
        return point.x;
    }

    @SuppressLint({"NewApi"})
    public int getScreenHeight() {
        Point point = new Point();
        this.mDefaultDisplay.getSize(point);
        return point.y;
    }

    public int getScreenOrientation() {
        int rotation = this.mDefaultDisplay.getRotation();
        if (rotation == 0 || rotation == 2) {
            return 1;
        }
        return (rotation == 1 || rotation != 3) ? 0 : 0;
    }

    public DisplayMetrics getDisplayMetrics() {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        this.mDefaultDisplay.getMetrics(displayMetrics);
        return displayMetrics;
    }
}
